package com.powernode.driver.controller;

import com.powernode.common.result.Result;
import com.powernode.driver.service.DriverInfoService;
import com.powernode.model.entity.driver.DriverSet;
import com.powernode.model.form.driver.DriverFaceModelForm;
import com.powernode.model.form.driver.UpdateDriverAuthInfoForm;
import com.powernode.model.vo.driver.DriverAuthInfoVo;
import com.powernode.model.vo.driver.DriverInfoVo;
import com.powernode.model.vo.driver.DriverLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 配送员信息控制器
 * 处理配送员信息相关的HTTP请求
 */
@Slf4j
@Tag(name = "配送员API接口管理")
@RestController
@RequestMapping(value = "/driver/info")
@SuppressWarnings({"unchecked", "rawtypes"})
public class DriverInfoController {
    // 配送员信息服务，用于处理业务逻辑
    @Resource
    private DriverInfoService driverInfoService;

    /**
     * 配送员登录接口
     *
     * @param code 微信小程序登录码
     * @return 包含配送员ID的响应结果
     */
    @Operation(summary = "配送员登录")
    @GetMapping("/login/{code}")
    public Result<Long> login(@PathVariable String code) {
        return Result.ok(driverInfoService.login(code));
    }

    /**
     * 获取配送员登录信息接口
     *
     * @param driverId 配送员ID
     * @return 包含配送员登录信息的响应结果
     */
    @Operation(summary = "获取配送员登录信息")
    @GetMapping("/getDriverLoginInfo/{driverId}")
    public Result<DriverLoginVo> getDriverLoginInfo(@PathVariable Long driverId) {
        return Result.ok(driverInfoService.getDriverLoginInfo(driverId));
    }

    /**
     * 获取配送员认证信息接口
     *
     * @param driverId 配送员ID
     * @return 包含配送员认证信息的响应结果
     */
    @Operation(summary = "获取配送员认证信息")
    @GetMapping("getDriverAuthInfo/{driverId}")
    public Result<DriverAuthInfoVo> getDriverAuthInfo(@PathVariable Long driverId) {
        return Result.ok(driverInfoService.getDriverAuthInfo(driverId));
    }

    /**
     * 更新配送员认证信息接口
     *
     * @param driverAuthInfoForm 包含配送员认证信息的表单对象
     * @return 包含更新结果的响应结果
     */
    @Operation(summary = "更新配送员认证信息")
    @PostMapping("updateDriverAuthInfo")
    public Result<Boolean> updateDriverAuthInfo(@RequestBody UpdateDriverAuthInfoForm driverAuthInfoForm) {
        return Result.ok(driverInfoService.updateDriverAuthInfo(driverAuthInfoForm));
    }

    /**
     * 创建配送员人脸模型接口
     *
     * @param driverFaceModelForm 包含配送员人脸模型信息的表单对象
     * @return 包含创建结果的响应结果
     */
    @Operation(summary = "创建配送员人脸模型")
    @PostMapping("createDriverFaceModel")
    public Result<Boolean> createDriverFaceModel(@RequestBody DriverFaceModelForm driverFaceModelForm) {
        return Result.ok(driverInfoService.createDriverFaceModel(driverFaceModelForm));
    }

    /**
     * 查询配送员的配送的个性设置接口
     *
     * @param driverId 配送员ID
     * @return 包含配送员个性设置的响应结果
     */
    @Operation(summary = "查询配送员的配送的个性设置")
    @GetMapping("getDriverSet/{driverId}")
    public Result<DriverSet> getDriverSet(@PathVariable Long driverId) {
        return Result.ok(driverInfoService.getDriverSet(driverId));
    }

    /**
     * 判断配送员当日是否进行过人脸识别
     *
     * @param driverId 配送员ID
     * @return 包含判断结果的响应结果
     */
    @Operation(summary = "判断配送员当日是否进行过人脸识别")
    @GetMapping("/isFaceRecognition/{driverId}")
    Result<Boolean> isFaceRecognition(@PathVariable("driverId") Long driverId) {
        return Result.ok(driverInfoService.isFaceRecognition(driverId));
    }

    /**
     * 验证配送员人脸接口
     *
     * @param driverFaceModelForm 包含配送员人脸模型信息的表单对象
     * @return 包含验证结果的响应结果
     */
    @Operation(summary = "验证配送员人脸")
    @PostMapping("/verifyDriverFace")
    public Result<Boolean> verifyDriverFace(@RequestBody DriverFaceModelForm driverFaceModelForm) {
        return Result.ok(driverInfoService.verifyDriverFace(driverFaceModelForm));
    }

    /**
     * 更新配送员接单状态接口
     *
     * @param driverId 配送员ID
     * @param status   配送员接单状态（0：不接单，1：接单）
     * @return 包含更新结果的响应结果
     */
    @Operation(summary = "更新配送员接单状态")
    @GetMapping("/updateServiceStatus/{driverId}/{status}")
    public Result<Boolean> updateServiceStatus(@PathVariable Long driverId, @PathVariable Integer status) {
        return Result.ok(driverInfoService.updateServiceStatus(driverId, status));
    }

    @Operation(summary = "获取配送员同显基本信息")
    @GetMapping("/getDriverInfoOrder/{driverId}")
    public Result<DriverInfoVo> getDriverInfoOrder(@PathVariable Long driverId) {
        return Result.ok(driverInfoService.getDriverInfoOrder(driverId));
    }
}

